// GLL.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "Game.h"

using namespace GLL;

class MyGameState : public GameState
{
	bool Ok2ExitGame()
	{
		return false;//theGame()->_input->IsKeyDown(VK_X);
	}

	virtual void OnEnter( GameState* from );

	bool OnExitGame();

	virtual bool Update(TimeMS TSLF);

	virtual void OnExit()
	{

	}
};

String rgmName("SceneThis");

class MyGameApp : public GameApp
{
public:
	Ogre::SceneManager* mSceneMgr;
	Ogre::Root* mRoot;
	Ogre::RenderWindow* mRenderWindow;

	MyGameApp()
	{
		pSN1 = pSN2 = pSN3 = 0;
	}

	void Createlight()
	{
		Ogre::ColourValue lightColour(1, 1, 1);

		// create a light
		Ogre::Light* light = mSceneMgr->createLight();
		light->setDiffuseColour(lightColour);
		light->setSpecularColour(1, 1, 1);
		light->setAttenuation(1500, 1, 0.0005f, 0);

		Ogre::SceneNode* lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, 30, 30));
		lightNode->attachObject(light);
	}

public:

	Ogre::SceneNode* pSN1;
	Ogre::SceneNode* pSN2;
	Ogre::SceneNode* pSN3;

};


void MyGameState::OnEnter( GameState* from )
{
	LvlSrdPtr srdLvl = theWorld()->_lvlMgr->Create(1);

	CamSrdPtr pCam = theWorld()->CreateCamera();
	srdLvl->AddCamera(pCam);
	pCam->SetPosition(Position3Df(15, 15, -20));
	pCam->SetLookAt(Position3Df(-10, 10, 0));

	//void TEST_LOAD();
	//TEST_LOAD();

	Object::ID id(Object::OT_Mesh, 1);
	LvlObjSrdPtr objPtr = srdLvl->CreateObject(id);
	objPtr->SetPropVal(ObjectMesh::OP_ModFile, String("jaiqua.mesh"));
	OCSkltnAnmtn* poa = GLL_NEW OCSkltnAnmtn;
	poa->SetAnimation("Walk");
	//poa->SetTimeRate(0);
	//poa->ScaleBone("Rbicept", 2.0f);
	objPtr->AddCom(poa);

	//GLL_LOG("Create %d, x(%d) y(%d)  ptr:%p\n", id.index, x, y, pjo);
	objPtr->PutToLoadQueue();

}

bool MyGameState::OnExitGame()
{
	void TEST_LOAD_EXIT();
	TEST_LOAD_EXIT();
	return true;
}

class MyOSApp : public GLL::OSApp
{
public:
	virtual void GetOSAppTitle(StringStream& out)
	{
		out << "FPS:"<< std::setprecision(4) << theGame()->GetFPS();
	}
};

void VeryFirstFunction();

int APIENTRY _tWinMain(HINSTANCE hInstance,
					   HINSTANCE hPrevInstance,
					   LPTSTR    lpCmdLine,
					   int       nCmdShow)
{
	VeryFirstFunction();

	MyGameState myState;
	MyGameApp gameApp;
	MyOSApp osa;
	osa.Start_CatchAllException(&gameApp, myState);
	return 0;
}



bool MyGameState::Update( TimeMS TSLF )
{

	return true;
}



//-----------------------------------------------------------------------------
void VeryFirstFunction()
{


}